#!/usr/bin/python

import sys
from Bio import SeqIO

sf = open(sys.argv[1], "rU")

record = SeqIO.read(sf, "fasta")

start = raw_input("Enter start: ")

stop = raw_input("Enter stop: ")

strand = raw_input("Enter strand (+ or -): ")

n = 3

triplets = []

if strand == "+":
    subseq = record.seq[int(start):int(stop)]
    num = len(subseq)
    print "Substring = ", subseq
    print "Length = ", num
    while n <= num:
        t = subseq[num-n:num-n+3]
        triplets.append(t)
        n += 3
else:
    subseq = record.seq[int(start):int(stop)].reverse_complement()
    num = len(subseq)
    print "Substring = ", subseq
    print "Length = ", num
    while n <= num:
        t = subseq[num-n:num-n+3]
        triplets.append(t)
        n += 3

print "Triplets: ",

m = -1

neg = -len(triplets)

while m >= neg:
    print triplets[m],
    m -= 1
